/*
 * @LastEditors: Seven
 * @LastEditTime: 2022-11-22 14:21:10
 */
import axios from 'axios';
import UtilVar from "@/config/UtilVar";

let baseUrl = UtilVar.baseUrl
export {
    baseUrl
};
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    return config;
}, function (error) {
    // 对请求错误做些什么
    console.log(error)
    return Promise.reject(error);
});
/**
 * @响应拦截
 */
axios.interceptors.response.use(response => {
    return response.data
}, error => {
    let err = {
        success: false,
        msg: "未知异常，请联系管理员！"
    }
    return Promise.reject(err)
})
/**
 * @封装get请求
 */
export const GET = async (url, params) => {
    try {
        const data = await axios.get(`${baseUrl}${url}`, {
            params: params,
        });
        const statusMap = new Map([
            ['本地疫情', [data.data.areaTree]],
            ['疫情分布', [data.data.areaTree]],
            ['全国疫情数据', [data.data.chinaTotal]],
            ['全国疫情新增趋势', [data.data.chinaDayList]],
            ['疫情人数排名', [data.data.areaTree]],
        ])
        const statusData = statusMap.get(params.status)
        return statusData[0];
    } catch (error) {
        return error;
    }
}
//没有基地址 访问根目录下文件
export const GETNOBASE = async (url, params) => {
    try {
        const data = await axios.get(url, {
            params: params,
        });
        return data;
    } catch (error) {
        return error;
    }
}